package com.dianping.cat.consumer.state.model.transform;

import com.dianping.cat.consumer.state.model.entity.Detail;
import com.dianping.cat.consumer.state.model.entity.Machine;
import com.dianping.cat.consumer.state.model.entity.Message;
import com.dianping.cat.consumer.state.model.entity.ProcessDomain;
import com.dianping.cat.consumer.state.model.entity.StateReport;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.xml.sax.Attributes;





















public class DefaultSaxMaker
  extends Object
  implements IMaker<Attributes>
{
  public Detail buildDetail(Attributes attributes) {
/*  39 */     String id = attributes.getValue("id");
/*  40 */     String total = attributes.getValue("total");
/*  41 */     String size = attributes.getValue("size");
/*  42 */     String totalLoss = attributes.getValue("totalLoss");
/*  43 */     Detail detail = new Detail((id == null) ? null : (Long)convert(Long.class, id, null));

/*  45 */     if (total != null) {
/*  46 */       detail.setTotal(((Long)convert(Long.class, total, Long.valueOf(0L))).longValue());
    }

/*  49 */     if (size != null) {
/*  50 */       detail.setSize(toNumber(size, "0.0", Integer.valueOf(0)).doubleValue());
    }

/*  53 */     if (totalLoss != null) {
/*  54 */       detail.setTotalLoss(((Long)convert(Long.class, totalLoss, Long.valueOf(0L))).longValue());
    }

/*  57 */     return detail;
  }



/*  62 */   public String buildIp(Attributes attributes) { throw new UnsupportedOperationException(); }



  public Machine buildMachine(Attributes attributes) {
/*  67 */     String ip = attributes.getValue("ip");
/*  68 */     String total = attributes.getValue("total");
/*  69 */     String totalLoss = attributes.getValue("totalLoss");
/*  70 */     String maxTps = attributes.getValue("maxTps");
/*  71 */     String avgTps = attributes.getValue("avgTps");
/*  72 */     String blockTotal = attributes.getValue("blockTotal");
/*  73 */     String blockLoss = attributes.getValue("blockLoss");
/*  74 */     String blockTime = attributes.getValue("blockTime");
/*  75 */     String pigeonTimeError = attributes.getValue("pigeonTimeError");
/*  76 */     String networkTimeError = attributes.getValue("networkTimeError");
/*  77 */     String dump = attributes.getValue("dump");
    String dumpLoss = attributes.getValue("dumpLoss");
/*  79 */     String size = attributes.getValue("size");
/*  80 */     String delaySum = attributes.getValue("delaySum");
/*  81 */     String delayAvg = attributes.getValue("delayAvg");
/*  82 */     String delayCount = attributes.getValue("delayCount");
/*  83 */     Machine machine = new Machine(ip);

/*  85 */     if (total != null) {
/*  86 */       machine.setTotal(((Long)convert(Long.class, total, Long.valueOf(0L))).longValue());
    }

/*  89 */     if (totalLoss != null) {
/*  90 */       machine.setTotalLoss(((Long)convert(Long.class, totalLoss, Long.valueOf(0L))).longValue());
    }

/*  93 */     if (maxTps != null) {
/*  94 */       machine.setMaxTps(toNumber(maxTps, "0.0", Integer.valueOf(0)).doubleValue());
    }

/*  97 */     if (avgTps != null) {
/*  98 */       machine.setAvgTps(toNumber(avgTps, "0.0", Integer.valueOf(0)).doubleValue());
    }

/* 101 */     if (blockTotal != null) {
/* 102 */       machine.setBlockTotal(((Long)convert(Long.class, blockTotal, Long.valueOf(0L))).longValue());
    }

/* 105 */     if (blockLoss != null) {
/* 106 */       machine.setBlockLoss(((Long)convert(Long.class, blockLoss, Long.valueOf(0L))).longValue());
    }

/* 109 */     if (blockTime != null) {
/* 110 */       machine.setBlockTime(((Long)convert(Long.class, blockTime, Long.valueOf(0L))).longValue());
    }

/* 113 */     if (pigeonTimeError != null) {
/* 114 */       machine.setPigeonTimeError(((Long)convert(Long.class, pigeonTimeError, Long.valueOf(0L))).longValue());
    }

/* 117 */     if (networkTimeError != null) {
/* 118 */       machine.setNetworkTimeError(((Long)convert(Long.class, networkTimeError, Long.valueOf(0L))).longValue());
    }

/* 121 */     if (dump != null) {
/* 122 */       machine.setDump(((Long)convert(Long.class, dump, Long.valueOf(0L))).longValue());
    }

/* 125 */     if (dumpLoss != null) {
/* 126 */       machine.setDumpLoss(((Long)convert(Long.class, dumpLoss, Long.valueOf(0L))).longValue());
    }

/* 129 */     if (size != null) {
/* 130 */       machine.setSize(toNumber(size, "0.0", Integer.valueOf(0)).doubleValue());
    }

/* 133 */     if (delaySum != null) {
/* 134 */       machine.setDelaySum(toNumber(delaySum, "0.0", Integer.valueOf(0)).doubleValue());
    }

/* 137 */     if (delayAvg != null) {
/* 138 */       machine.setDelayAvg(toNumber(delayAvg, "0.0", Integer.valueOf(0)).doubleValue());
    }

/* 141 */     if (delayCount != null) {
/* 142 */       machine.setDelayCount(((Integer)convert(Integer.class, delayCount, Integer.valueOf(0))).intValue());
    }

/* 145 */     return machine;
  }


  public Message buildMessage(Attributes attributes) {
/* 150 */     String id = attributes.getValue("id");
/* 151 */     String time = attributes.getValue("time");
/* 152 */     String total = attributes.getValue("total");
/* 153 */     String totalLoss = attributes.getValue("totalLoss");
/* 154 */     String dump = attributes.getValue("dump");
/* 155 */     String dumpLoss = attributes.getValue("dumpLoss");
/* 156 */     String size = attributes.getValue("size");
/* 157 */     String delaySum = attributes.getValue("delaySum");
/* 158 */     String delayCount = attributes.getValue("delayCount");
/* 159 */     String pigeonTimeError = attributes.getValue("pigeonTimeError");
/* 160 */     String networkTimeError = attributes.getValue("networkTimeError");
/* 161 */     String blockTotal = attributes.getValue("blockTotal");
/* 162 */     String blockLoss = attributes.getValue("blockLoss");
/* 163 */     String blockTime = attributes.getValue("blockTime");
/* 164 */     Message message = new Message((id == null) ? null : (Long)convert(Long.class, id, null));

/* 166 */     if (time != null) {
/* 167 */       message.setTime(toDate(time, "yyyy-MM-dd HH:mm:ss", null));
    }

/* 170 */     if (total != null) {
/* 171 */       message.setTotal(((Long)convert(Long.class, total, Long.valueOf(0L))).longValue());
    }

/* 174 */     if (totalLoss != null) {
/* 175 */       message.setTotalLoss(((Long)convert(Long.class, totalLoss, Long.valueOf(0L))).longValue());
    }

/* 178 */     if (dump != null) {
/* 179 */       message.setDump(((Long)convert(Long.class, dump, Long.valueOf(0L))).longValue());
    }

/* 182 */     if (dumpLoss != null) {
/* 183 */       message.setDumpLoss(((Long)convert(Long.class, dumpLoss, Long.valueOf(0L))).longValue());
    }

/* 186 */     if (size != null) {
/* 187 */       message.setSize(toNumber(size, "0.0", Integer.valueOf(0)).doubleValue());
    }

/* 190 */     if (delaySum != null) {
/* 191 */       message.setDelaySum(toNumber(delaySum, "0.0", Integer.valueOf(0)).doubleValue());
    }

/* 194 */     if (delayCount != null) {
/* 195 */       message.setDelayCount(((Integer)convert(Integer.class, delayCount, Integer.valueOf(0))).intValue());
    }

/* 198 */     if (pigeonTimeError != null) {
/* 199 */       message.setPigeonTimeError(((Long)convert(Long.class, pigeonTimeError, Long.valueOf(0L))).longValue());
    }

/* 202 */     if (networkTimeError != null) {
/* 203 */       message.setNetworkTimeError(((Long)convert(Long.class, networkTimeError, Long.valueOf(0L))).longValue());
    }

/* 206 */     if (blockTotal != null) {
/* 207 */       message.setBlockTotal(((Long)convert(Long.class, blockTotal, Long.valueOf(0L))).longValue());
    }

/* 210 */     if (blockLoss != null) {
/* 211 */       message.setBlockLoss(((Long)convert(Long.class, blockLoss, Long.valueOf(0L))).longValue());
    }

/* 214 */     if (blockTime != null) {
/* 215 */       message.setBlockTime(((Long)convert(Long.class, blockTime, Long.valueOf(0L))).longValue());
    }

/* 218 */     return message;
  }


  public ProcessDomain buildProcessDomain(Attributes attributes) {
/* 223 */     String name = attributes.getValue("name");
/* 224 */     String total = attributes.getValue("total");
/* 225 */     String totalLoss = attributes.getValue("totalLoss");
/* 226 */     String size = attributes.getValue("size");
/* 227 */     String avg = attributes.getValue("avg");
/* 228 */     ProcessDomain processDomain = new ProcessDomain(name);

/* 230 */     if (total != null) {
/* 231 */       processDomain.setTotal(((Long)convert(Long.class, total, Long.valueOf(0L))).longValue());
    }

/* 234 */     if (totalLoss != null) {
/* 235 */       processDomain.setTotalLoss(((Long)convert(Long.class, totalLoss, Long.valueOf(0L))).longValue());
    }

/* 238 */     if (size != null) {
/* 239 */       processDomain.setSize(toNumber(size, "0.0", Integer.valueOf(0)).doubleValue());
    }

/* 242 */     if (avg != null) {
/* 243 */       processDomain.setAvg(toNumber(avg, "0.0", Integer.valueOf(0)).doubleValue());
    }

/* 246 */     return processDomain;
  }


  public StateReport buildStateReport(Attributes attributes) {
/* 251 */     String domain = attributes.getValue("domain");
/* 252 */     String startTime = attributes.getValue("startTime");
/* 253 */     String endTime = attributes.getValue("endTime");
/* 254 */     StateReport stateReport = new StateReport(domain);

/* 256 */     if (startTime != null) {
/* 257 */       stateReport.setStartTime(toDate(startTime, "yyyy-MM-dd HH:mm:ss", null));
    }

/* 260 */     if (endTime != null) {
/* 261 */       stateReport.setEndTime(toDate(endTime, "yyyy-MM-dd HH:mm:ss", null));
    }

/* 264 */     return stateReport;
  }


  protected <T> T convert(Class<T> type, String value, T defaultValue) {
/* 269 */     if (value == null || value.length() == 0) {
/* 270 */       return defaultValue;
    }

/* 273 */     if (type == Boolean.class || type == boolean.class)
/* 274 */       return (T)Boolean.valueOf(value); 
/* 275 */     if (type == Integer.class || type == int.class)
/* 276 */       return (T)Integer.valueOf(value); 
/* 277 */     if (type == Long.class || type == long.class)
/* 278 */       return (T)Long.valueOf(value); 
/* 279 */     if (type == Short.class || type == short.class)
/* 280 */       return (T)Short.valueOf(value); 
/* 281 */     if (type == Float.class || type == float.class)
/* 282 */       return (T)Float.valueOf(value); 
/* 283 */     if (type == Double.class || type == double.class)
/* 284 */       return (T)Double.valueOf(value); 
/* 285 */     if (type == Byte.class || type == byte.class)
/* 286 */       return (T)Byte.valueOf(value); 
/* 287 */     if (type == Character.class || type == char.class) {
/* 288 */       return (T)Character.valueOf(value.charAt(0));
    }
/* 290 */     return (T)value;
  }


  protected Date toDate(String str, String format, Date defaultValue) {
/* 295 */     if (str == null || str.length() == 0) {
/* 296 */       return defaultValue;
    }

    try {
/* 300 */       return (new SimpleDateFormat(format)).parse(str);
/* 301 */     } catch (ParseException e) {
/* 302 */       throw new RuntimeException(String.format("Unable to parse date(%s) in format(%s)!", new Object[] { str, format }), e);
    }
  }

  protected Number toNumber(String str, String format, Number defaultValue) {
/* 307 */     if (str == null || str.length() == 0) {
/* 308 */       return defaultValue;
    }

    try {
/* 312 */       return (new DecimalFormat(format)).parse(str);
/* 313 */     } catch (ParseException e) {
/* 314 */       throw new RuntimeException(String.format("Unable to parse number(%s) in format(%s)!", new Object[] { str, format }), e);
    }
  }
}


/* Location:              /Users/hanfei/Documents/apache-tomcat-9.0.24/webapps/cat/WEB-INF/lib/cat-consumer-3.0.0.jar!/com/dianping/cat/consumer/state/model/transform/DefaultSaxMaker.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       1.0.7
 */